<?php
class User_Validation
{
	public static function register(& $data)
	{
		$data = Validation::factory($data)
			->pre_filter('trim',true)
			->add_rules('username','required')
			->add_rules('email','required','valid::email','User_Validation::email_not_exists')
			->add_rules('password','required')
			->add_rules('password_confirm','required','matches[password]');
		if(!empty($data['link']))
		{
			$data->add_rules('link','valid::url');
		}
		return $data;
	}

	public static function email_not_exists($validation)
	{
		$emails = user::get_emails();
		if(in_array($validation['email'],$emails))
		{
			return false;
		}
		return true;
	}
}
